## Morocco

rm(list=ls())
library(foreign)


# Labor
mydata1 <- read.table("E:/labor.txt")
attach(mydata1)

matcoeflabor <- matrix(0,16,4)

for (i in 1:16) {

  matcoeflabor[i,1] <- i*.2-1.7
  matcoeflabor[i,2] <- mydata1[i,1]
  matcoeflabor[i,3] <- mydata1[i,1]-1.96*mydata1[i,2]
  matcoeflabor[i,4] <- mydata1[i,1]+1.96*mydata1[i,2]

  }
  
# Fiscal
mydata2 <- read.table("E:/fiscal.txt")
attach(mydata2)

matcoeffiscal <- matrix(0,16,4)

for (i in 1:16) {

  matcoeffiscal[i,1] <- i*.2-1.7
  matcoeffiscal[i,2] <- mydata2[i,1]
  matcoeffiscal[i,3] <- mydata2[i,1]-1.96*mydata2[i,2]
  matcoeffiscal[i,4] <- mydata2[i,1]+1.96*mydata2[i,2]

  }
  
# Security
mydata3 <- read.table("E:/security.txt")
attach(mydata3)

matcoefsecurity <- matrix(0,16,4)

for (i in 1:16) {

  matcoefsecurity[i,1] <- i*.2-1.7
  matcoefsecurity[i,2] <- mydata3[i,1]
  matcoefsecurity[i,3] <- mydata3[i,1]-1.96*mydata3[i,2]
  matcoefsecurity[i,4] <- mydata3[i,1]+1.96*mydata3[i,2]

  }
  
# Culture
mydata4 <- read.table("E:/culture.txt")
attach(mydata4)

matcoefculture <- matrix(0,16,4)

for (i in 1:16) {

  matcoefculture[i,1] <- i*.2-1.7
  matcoefculture[i,2] <- mydata4[i,1]
  matcoefculture[i,3] <- mydata4[i,1]-1.96*mydata4[i,2]
  matcoefculture[i,4] <- mydata4[i,1]+1.96*mydata4[i,2]

  }


## Plot

pdf("figure1.pdf")
par(mfrow=c(2,2))
par(mar=c(5,5,5,5))

plot(matcoeflabor[,1], matcoeflabor[,2], type="l", lty=1, xlim=c(-1.5,1.5), ylim=c(-.5,1.5), xaxt="n", yaxt="n", xlab="Economic underdevelopment", ylab="Heightened labor market threat perception \n of African migrants", cex.lab=.8, main="Economic Theory: Underdevelopment & \n Greater Opposition to African Migrants", cex.main=1.0)
      #customlabels<-seq(-1.5,1.5,by=1.5)
      #axis(1,at=customlabels,labels=customlabels)
      customlabels<-seq(-.5,1.5,by=.5)
      axis(2,at=customlabels,labels=customlabels)
      par(new=TRUE)  
      plot(matcoeflabor[,1], matcoeflabor[,3], type="l", lty=0, xlim=c(-1.5,1.5), ylim=c(-.5,1.5), xaxt="n", yaxt="n", xlab="Economic underdevelopment", ylab="Heightened labor market threat perception \n of African migrants", cex.lab=.8, main="Economic Theory: Underdevelopment & \n Greater Opposition to African Migrants", cex.main=1.0)
      #customlabels<-seq(-1.5,1.5,by=1.5)
      #axis(1,at=customlabels,labels=customlabels)
      customlabels<-seq(-.5,1.5,by=.5)
      axis(2,at=customlabels,labels=customlabels)
      par(new=TRUE)
      plot(matcoeflabor[,1], matcoeflabor[,4], type="l", lty=0, xlim=c(-1.5,1.5), ylim=c(-.5,1.5), xaxt="n", yaxt="n", xlab="Economic underdevelopment", ylab="Heightened labor market threat perception \n of African migrants", cex.lab=.8, main="Economic Theory: Underdevelopment & \n Greater Opposition to African Migrants", cex.main=1.0)
      #customlabels<-seq(-1.5,1.5,by=1.5)
      #axis(1,at=customlabels,labels=customlabels)
      customlabels<-seq(-.5,1.5,by=.5)
      axis(2,at=customlabels,labels=customlabels)
      abline(h=0,lty=6)
      aa<- c(seq(-1.5,1.5,by=.2),rev(c(seq(-1.5,1.5,by=.2))))
      bb <- c(matcoeflabor[,3], rev(matcoeflabor[,4]))
      polygon(aa,bb,col="gray", density=40)
      axis(1,at=-1.5, "Developed", cex.axis=0.8) 
      axis(1,at=1.5, "Underdeveloped", cex.axis=0.8) 
            
plot(matcoeffiscal[,1], matcoeffiscal[,2], type="l", lty=1, xlim=c(-1.5,1.5), ylim=c(-.5,1.5), xaxt="n", yaxt="n", xlab="Economic underdevelopment", ylab="Heightened fiscal threat perception \n of African migrants", cex.lab=.8, main="Economic Theory: Underdevelopment & \n Greater Opposition to African Migrants", cex.main=1.0)
      #customlabels<-seq(-1.5,1.5,by=1.5)
      #axis(1,at=customlabels,labels=customlabels)
      customlabels<-seq(-.5,1.5,by=.5)
      axis(2,at=customlabels,labels=customlabels)
      par(new=TRUE)  
      plot(matcoeffiscal[,1], matcoeffiscal[,3], type="l", lty=0, xlim=c(-1.5,1.5), ylim=c(-.5,1.5), xaxt="n", yaxt="n", xlab="Economic underdevelopment", ylab="Heightened fiscal threat perception \n of African migrants", cex.lab=.8, main="Economic Theory: Underdevelopment & \n Greater Opposition to African Migrants", cex.main=1.0)
      #customlabels<-seq(-1.5,1.5,by=1.5)
      #axis(1,at=customlabels,labels=customlabels)
      customlabels<-seq(-.5,1.5,by=.5)
      axis(2,at=customlabels,labels=customlabels)
      par(new=TRUE)
      plot(matcoeffiscal[,1], matcoeffiscal[,4], type="l", lty=0, xlim=c(-1.5,1.5), ylim=c(-.5,1.5), xaxt="n", yaxt="n", xlab="Economic underdevelopment", ylab="Heightened fiscal threat perception \n of African migrants", cex.lab=.8, main="Economic Theory: Underdevelopment & \n Greater Opposition to African Migrants", cex.main=1.0)
      #customlabels<-seq(-1.5,1.5,by=1.5)
      #axis(1,at=customlabels,labels=customlabels)
      customlabels<-seq(-.5,1.5,by=.5)
      axis(2,at=customlabels,labels=customlabels)
      abline(h=0,lty=6)
      cc<- c(seq(-1.5,1.5,by=.2),rev(c(seq(-1.5,1.5,by=.2))))
      dd <- c(matcoeffiscal[,3], rev(matcoeffiscal[,4]))
      polygon(cc,dd,col="gray", density=40)      
      axis(1,at=-1.5, "Developed", cex.axis=0.8) 
      axis(1,at=1.5, "Underdeveloped", cex.axis=0.8) 
      
plot(matcoefsecurity[,1], matcoefsecurity[,2], type="l", lty=1, xlim=c(-1.5,1.5), ylim=c(-.5,1.5), xaxt="n", yaxt="n", xlab="Economic underdevelopment", ylab="Heightened security threat perception \n of African migrants", cex.lab=.8, main="Security Theory: Underdevelopment & \n Greater Opposition to African Migrants", cex.main=1.0)
      #customlabels<-seq(-1.5,1.5,by=1.5)
      #axis(1,at=customlabels,labels=customlabels)
      customlabels<-seq(-.5,1.5,by=.5)
      axis(2,at=customlabels,labels=customlabels)
      par(new=TRUE)  
      plot(matcoefsecurity[,1], matcoefsecurity[,3], type="l", lty=0, xlim=c(-1.5,1.5), ylim=c(-.5,1.5), xaxt="n", yaxt="n", xlab="Economic underdevelopment", ylab="Heightened security threat perception \n of African migrants", cex.lab=.8, main="Security Theory: Underdevelopment & \n Greater Opposition to African Migrants", cex.main=1.0)
      #customlabels<-seq(-1.5,1.5,by=1.5)
      #axis(1,at=customlabels,labels=customlabels)
      customlabels<-seq(-.5,1.5,by=.5)
      axis(2,at=customlabels,labels=customlabels)
      par(new=TRUE)
      plot(matcoefsecurity[,1], matcoefsecurity[,4], type="l", lty=0, xlim=c(-1.5,1.5), ylim=c(-.5,1.5), xaxt="n", yaxt="n", xlab="Economic underdevelopment", ylab="Heightened security threat perception \n of African migrants", cex.lab=.8, main="Security Theory: Underdevelopment & \n Greater Opposition to African Migrants", cex.main=1.0)
      #customlabels<-seq(-1.5,1.5,by=1.5)
      #axis(1,at=customlabels,labels=customlabels)
      customlabels<-seq(-.5,1.5,by=.5)
      axis(2,at=customlabels,labels=customlabels)
      abline(h=0,lty=6)
      ee<- c(seq(-1.5,1.5,by=.2),rev(c(seq(-1.5,1.5,by=.2))))
      ff <- c(matcoefsecurity[,3], rev(matcoefsecurity[,4]))
      polygon(ee,ff,col="gray", density=40) 
      axis(1,at=-1.5, "Developed", cex.axis=0.8) 
      axis(1,at=1.5, "Underdeveloped", cex.axis=0.8) 
            
plot(matcoefculture[,1], matcoefculture[,2], type="l", lty=1, xlim=c(-1.5,1.5), ylim=c(-.5,1.5), xaxt="n", yaxt="n", xlab="Economic underdevelopment", ylab="Heightened cultural threat perception \n of African migrants", cex.lab=.8, main="Cultural Theory: Underdevelopment & \n Greater Opposition to African Migrants", cex.main=1.0)
      #customlabels<-seq(-1.5,1.5,by=1.5)
      #axis(1,at=customlabels,labels=customlabels)
      customlabels<-seq(-.5,1.5,by=.5)
      axis(2,at=customlabels,labels=customlabels)
      par(new=TRUE)  
      plot(matcoefculture[,1], matcoefculture[,3], type="l", lty=0, xlim=c(-1.5,1.5), ylim=c(-.5,1.5), xaxt="n", yaxt="n", xlab="Economic underdevelopment", ylab="Heightened cultural threat perception \n of African migrants", cex.lab=.8, main="Cultural Theory: Underdevelopment & \n Greater Opposition to African Migrants", cex.main=1.0)
      #customlabels<-seq(-1.5,1.5,by=1.5)
      #axis(1,at=customlabels,labels=customlabels)
      customlabels<-seq(-.5,1.5,by=.5)
      axis(2,at=customlabels,labels=customlabels)
      par(new=TRUE)
      plot(matcoefculture[,1], matcoefculture[,4], type="l", lty=0, xlim=c(-1.5,1.5), ylim=c(-.5,1.5), xaxt="n", yaxt="n", xlab="Economic underdevelopment", ylab="Heightened cultural threat perception \n of African migrants", cex.lab=.8, main="Cultural Theory: Underdevelopment & \n Greater Opposition to African Migrants", cex.main=1.0)
      #customlabels<-seq(-1.5,1.5,by=1.5)
      #axis(1,at=customlabels,labels=customlabels)
      customlabels<-seq(-.5,1.5,by=.5)
      axis(2,at=customlabels,labels=customlabels)
      abline(h=0,lty=6)
      gg<- c(seq(-1.5,1.5,by=.2),rev(c(seq(-1.5,1.5,by=.2))))
      hh <- c(matcoefculture[,3], rev(matcoefculture[,4]))
      polygon(gg,hh,col="gray", density=40) 
      axis(1,at=-1.5, "Developed", cex.axis=0.8) 
      axis(1,at=1.5, "Underdeveloped", cex.axis=0.8) 
      
    dev.off()
      
      

